package com.aholu.wicket;

import org.apache.wicket.authroles.authentication.AuthenticatedWebSession;
import org.apache.wicket.authroles.authorization.strategies.role.Roles;
import org.apache.wicket.request.Request;

import com.aholu.dao.DaoFactory;
import com.aholu.dao.UserDao;
import com.aholu.model.User;

public class WebSession extends AuthenticatedWebSession {

	private User user;
	private UserDao dao = DaoFactory.getUserDao();

	public WebSession(Request request) {
		super(request);
	}

	public User getLoggedUser() {
		return user;
	}

	@Override
	public Roles getRoles() {
		if (user == null)
			return new Roles();
		return new Roles(user.getRole());
	}

	@Override
	public boolean authenticate(String username, String password) {
		user = dao.findByUserNameAndPass(username, password);

		if (user == null)
			return false;
		else
			return true;

	}

}
